home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / BEERSRC.ZIP / VOCSTRIP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-16  |  3.0 KB  |  140 lines

  1.  
  2.  
  3. #ifndef __COMPACT__
  4.    #error Memory Model must be compact
  5. #endif
  6.  
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <conio.h>
  10. #include <stdio.h>
  11. #include <alloc.h>
  12. #include <io.h>
  13. #include <fcntl.h>
  14. #include <sys\stat.h>
  15. #include <dos.h>
  16.  
  17.  
  18. #include "sound.h"
  19.  
  20. struct sndstrc lall;
  21.  
  22.  
  23. int do_the_nasty_job(char *infile, char *outfile)
  24. {
  25.    int   in, out;
  26.    long  size, objsize;
  27.    char  *ptr;
  28.    int   y;
  29.    char  file[80];
  30.    int   voc;
  31.    int   ref, tmp1, tmp2;
  32.    unsigned i;
  33.  
  34.  
  35.    strcpy(file, infile); strcat(file, ".RAW");
  36.    in = open(file, O_RDONLY | O_BINARY, S_IREAD);
  37.    voc = 0;
  38.    if (in == -1) {
  39.       strcpy(file, infile); strcat(file, ".VOC");
  40.       in = open(file, O_RDONLY | O_BINARY, S_IREAD);
  41.       voc = 1;
  42.       if (in == -1) {
  43.      perror("readobj : ");
  44.      return -1;
  45.       }
  46.    }
  47.  
  48.    out = open(outfile, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IWRITE);
  49.    if (out == -1) {
  50.       perror("writefile : ");
  51.       return -1;
  52.    }
  53.  
  54.    ptr = malloc(60000);
  55.  
  56.    if (voc) {
  57.       size = objsize = (filelength(in) - 0x21) & 0xfffffffel;
  58.       lseek(in, 0x20, SEEK_SET);
  59.    } else {
  60.       size = objsize = filelength(in);
  61.    }
  62.    lall.len = size;
  63.  
  64.    write(out, &lall, sizeof(struct sndstrc));
  65.  
  66.    ref = 0;
  67.    read(in, &ref, 1);
  68.    write(out, &ref, 1);
  69.  
  70.    y = wherey();
  71.    while(size > 60000) {
  72.       gotoxy(1, y); printf("%d %% completed.", 100*(objsize-size)/objsize);
  73.       read(in, ptr, 60000);
  74. //      if (lall.flags & SND_PACKED4) {
  75. //     for (i = 0; i < 30000; i+=2) {
  76. //        tmp1 = ptr[i]-ref;
  77. //        if (tmp1 > 7) tmp1 = 7; else if (tmp1 < -8) tmp1 = -8;
  78. //        ref += tmp1;
  79. //        tmp2 = ptr[i+1]-ref;
  80. //        if (tmp2 > 7) tmp2 = 7; else if (tmp2 < -8) tmp2 = -8;
  81. //        ref += tmp2;
  82. //        ptr[i/2] = (char)(tmp1 & 0xf) | (tmp2 << 4);
  83. //     }
  84. //     write(out, ptr, 30000);
  85. //     } else {
  86.      write(out, ptr, 60000);
  87. //      }
  88.       size -= 60000;
  89.    }
  90.    read(in, ptr, size);
  91.    write(out, ptr, size);
  92.    gotoxy(1, y); printf("100 %% completed.\n");
  93.  
  94.    free(ptr);
  95.  
  96.    close(out); close(in);
  97.  
  98.    return 0;
  99. }
  100.  
  101.  
  102.  
  103. void main(void)
  104. {
  105.    char   infile[80], outfile[80];
  106.    char   text[80];
  107.    int    filvar;
  108.  
  109.  
  110.    printf("\n\nVoc Stripper Ver 2.0 [c] 1993 Alpha-Helix.\n\n");
  111.    printf("Input File [.RAW || .VOC]: ");
  112.    fflush(stdin);
  113.    scanf("%s", infile);
  114.    printf("Sound File [.SND]: ");
  115.    fflush(stdin);
  116.    scanf("%s", outfile);
  117.    strcat(outfile, ".SND");
  118.    printf("Sampling Rate [15]: ");
  119.    fflush(stdin);
  120.    gets(text);
  121.    if (strlen(text) == 0) lall.samplerate = 15;
  122.    else lall.samplerate = atoi(text);
  123.    printf("Packed to 4 bit [y]: ");
  124.    fflush(stdin);
  125.    gets(text);
  126.    lall.flags = SND_PACKED4;
  127.    if (strlen(text) != 0) {
  128.       if (text[0] == 'n') lall.flags = 0;
  129.    }
  130.    printf("Priority [5]: ");
  131.    fflush(stdin);
  132.    gets(text);
  133.    if (strlen(text) == 0) lall.priority = 5;
  134.    else lall.priority = atoi(text);
  135.    do_the_nasty_job(infile, outfile);
  136.  
  137. }
  138.  
  139.  
  140.